#! /bin/bash
#
# Get source revision
#

ECHO=echo
SVN_INFO="svn info --non-interactive"

HOSTNAME="hostname"
DATE="date +%Y-%m-%d_%H:%M:%S"
REVISION_PREFIX="Build_SVN_R"

default_revision()
{
    ${ECHO} ${REVISION_PREFIX}`${DATE}`@`${HOSTNAME}`
    exit 0
}

svn_revision=`${SVN_INFO} ${PWD} 2>/dev/null | grep '^Last Changed Rev'`
if [[ $? != 0 ]]
then
    #Failed
    default_revision
fi

svn_url=`${SVN_INFO} $1 2>/dev/null | grep '^URL:' |awk '{print $NF}'`
if [[ $? != 0 ]]
then
    #Failed
    default_revision
fi

svn_url=`basename ${svn_url}`
if [[ $? != 0 ]]
then
    #Failed
    default_revision
fi

svn_revision=`echo ${svn_revision} | awk '{print $NF}'`
if [[ $? != 0 ]]
then
    #Failed
    default_revision
fi

svn_author=`${SVN_INFO} ${PWD} 2>/dev/null | grep '^Last Changed Author'`
svn_author=`echo ${svn_author} | awk '{print $NF}'`
if [[ $? != 0 ]]
then
    #Failed
    default_revision
fi
${ECHO} "${REVISION_PREFIX}${svn_revision}_${svn_author}_${svn_url}"
exit 0

# vim:et:sw=4:ts=4

